#pragma once

#include "d3d9.h"
#include "d3dx9.h"
#include <vector>
#include "ModelManager.h"
#include "ObstacleManager.h"
#include "Camera.h"
// Add pragma comments so we do not have to change
// the project dependencies
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

struct s_EnergyPowerUp
{
	D3DXMATRIX	worldMat, scaleMat, rotMat, transMat;
	D3DXVECTOR3	vecPos;
	bool		bActive;
	// AABB members
	D3DXVECTOR3			vecBBMin;
	D3DXVECTOR3			vecBBMax;
	D3DXVECTOR3			vecModelBounds[8];
	D3DXVECTOR3			worldBBmin;
	D3DXVECTOR3			worldBBmax;
	// AABB members (SECOND SET)
	D3DXVECTOR3			vecMagBBMin;
	D3DXVECTOR3			vecMagBBMax;
	D3DXVECTOR3			vecMagModelBounds[8];
	D3DXVECTOR3			worldMagBBmin;
	D3DXVECTOR3			worldMagBBmax;
};

class PowerUps
{
private:
	// Singleton instance
	static PowerUps*	m_PowerUpsInstance;
	// Pointer to the D3D Device
	IDirect3DDevice9*	m_Device;
	// Mesh to use for the power ups
	ID3DXMesh*			m_PowerUpMesh;
	// Testing meshes for collision
	ID3DXMesh*			m_BBMesh;
	ID3DXMesh*			m_MagnetMesh;
	// Count to keep track of how many power ups there is
	short				sPowerCount;
	short				sFightPowerUps;
	// Vector to hold the distance for pull effect
	D3DXVECTOR3			vecDistance;
	float				fSpeed;
	// Create the vector to hold the power ups
	std::vector<s_EnergyPowerUp*>	powerUpList;
	// Pointer to the model manager
	ModelManager*		m_ModelMan;
	// Pointer to the camera
	Camera*				m_pCam;
	// Material for the power ups
	D3DMATERIAL9		m_PowerMat;
	// Boundaries of where they can be created
	short				sXMax;
	short				sXMin;
	short				sZMax;
	short				sZMin;

public:
	PowerUps(void);
	~PowerUps(void);

	// Singleton functions
	static PowerUps* GetInstance(void);
	void DeletePowerInstance(void);
	// Initialize the power ups
	void InitPowerUps(IDirect3DDevice9* m_pD3DDevice);
	// Create, update, & render power ups
	short CreatePowerUps(short iPowerUpCount);
	void UpdatePowerUps(short sCheckpointPower, bool bFightDone);
	void StartPull(int iPowerID, float fDeltaTime);
	void RenderPowerUps(void);
	// Collision functions
	void CalculateWorldBB(int iPowerID);
	void CalculateMagnetWorldBB(int iPowerID);
	bool CollisionDetection(int iPowerID);
	bool MagnetCollisionDetection(int iPowerID);
	// Destroying power ups
	void DestroyPowerUps(void);
	void ShutdownPowerUps(void);
};
